<?php

namespace app\admin\dao;

use app\common\model\Access;
use ShidianUtil\Thinkphp\Dao\DaoTrait;

/**
 * AccessDao 数据访问对象
 * Class AccessDao
 * @package app\admin\dao
 * @method Access findByPK(?int $id, $field = true)
 * @method \think\Collection selectAll(?int $page, ?int $page_size, $field = true)
 * @method Access insertActive(array $params, array $allow_field = [])
 * @method Access updateActive(Access $model, array $params, array $allow_field = [])
 * @method Access findAndUpdateActive(int $id, array $params, array $allow_field = [])
 * @method Access updateActiveByClosure(\Closure $closure, array $params, array $allow_field = [])
 * @method void deleteModel(Access $model)
 * @method void deleteById(int|array|\Closure $id, bool $force = false)
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037579
 * @link https://www.kancloud.cn/manual/think-orm/1257998
 * @link https://www.kancloud.cn/thinkphp/master-database-and-model/265551
 */
class AccessDao
{
    use DaoTrait;

    /**
     * @var Access
     */
    private $baseModel;

    /**
     * AccessDao constructor.
     */
    public function __construct()
    {
        $this->baseModel = Access::class;
    }

    public function select()
    {
        return Access::where('level', 0)
            ->with([
                'sub' => fn($query) => $query->order('ord', 'ASC'),
            ])->order('ord', 'ASC')
            ->select();
    }
}
